<style>
    .table>thead>tr>th{text-align: center}
    .table>tbody>tr>td{vertical-align: middle; text-align: center}
</style>
<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-12">
            <h3 class="page-header">
                <span>数据统计</span>
            </h3>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <ul class="nav nav-tabs" id="myTab">
                        <li><a href="{:U('User/Questionnaire/statistics',array('id' => $id))}">总概</a></li>
                        <li><a href="{:U('User/Questionnaire/statisticsDate',array('id' => $id))}">最新数据</a></li>
                        <li class="active"><a href="javascript:;">用户行为</a></li>
                        <li><a href="{:U('User/Questionnaire/statisticsOption',array('id' => $id))}">选题统计</a></li>
                    </ul>
                </div>
                <div class="panel-body">
                    <div class="form-horizontal">
                        <div class="tab-content">
                            <div class="tab-pane active">
                                <form class="" role="form">
                                    <div class="container">
                                        <div class="row" style="display: none">
                                            <!--前缀-->
                                            <div class="form-group col-lg-3">
                                                <div class="input-group">
                                                    <span class="input-group-addon">问题1</span>
                                                    <select class="form-control" name="question1" id="question1">
                                                        <?php
                                                echo "<option value='0'>--请选择--</option>";
                                                        foreach($question_list as $question){
                                                            echo "<option value='" . $question['id'] . "'>" . $question['title'] . "</option>";
                                                        }?>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group col-lg-1"></div>
                                            <div class="form-group col-lg-3">
                                                <div class="input-group">
                                                    <span class="input-group-addon">答案1</span>
                                                    <select class="form-control" name="value1" id="value1">
                                                        <option value='0'>--请选择--</option>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="row" style="display: none">
                                            <!--前缀-->
                                            <div class="form-group col-lg-3">
                                                <div class="input-group">
                                                    <span class="input-group-addon">问题2</span>
                                                    <select class="form-control" name="question2" id="question2">
                                                        <?php
                                                echo "<option value='0'>--请选择--</option>";
                                                        foreach($question_list as $question){
                                                        echo "<option value='" . $question['id'] . "'>" . $question['title'] . "</option>";
                                                        }?>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group col-lg-1"></div>
                                            <div class="form-group col-lg-3">
                                                <div class="input-group">
                                                    <span class="input-group-addon">答案2</span>
                                                    <select class="form-control" name="value2"  id="value2">
                                                        <option value='0'>--请选择--</option>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <!--前缀-->
                                            <div class="form-group col-lg-3">
                                                <div class="input-group">
                                                    <span class="input-group-addon">问题</span>
                                                    <select class="form-control" name="question3"  id="question3">
                                                        <?php
                                                echo "<option value='0'>--请选择--</option>";
                                                        foreach($question_list as $question){
                                                        echo "<option value='" . $question['id'] . "'>" . $question['title'] . "</option>";
                                                        }?>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group col-lg-1"></div>
                                            <div class="form-group col-lg-3">
                                                <div class="input-group">
                                                    <span class="input-group-addon">答案</span>
                                                    <select class="form-control" name="value3"  id="value3">
                                                        <option value='0'>--请选择--</option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group col-lg-1"></div>
                                            <button class="btn btn-success" id="filter">筛选</button>
                                            <button class="btn btn-default" onclick="return empty_cond();">清空</button>
                                        </div>
                                    </div>
                                </form>
                                <div class="panel-heading">
                                    <a href="javascript:;" id="deleteAll" class="btn btn-danger">删除</a>
                                    <button style="float:right" type="button" onclick="return download();" class="btn btn-info">导出</button>
                                </div>
                                <div class="panel-body">
                                    <div class="table-responsive">
                                        <table class="table table-bordered">
                                            <thead>
                                                <tr>
                                                    <th width="5%"><input type="checkbox" id="selectAll"></th>
                                                    <th width="5%">编号</th>
                                                    <th width="20%">用户</th>
                                                    <th width="10%">开始答题</th>
                                                    <th width="8%">答题时长</th>
                                                    <th width="5%">得分</th>
                                                    <th width="10%">头像</th>
                                                    <th width="15%">昵称</th>
                                                    <th style="width: 100px;">操作</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                            <volist name="list" id="item">
                                                <tr>
                                                    <td><input type="checkbox" name="ids" value="{$item.id}"></td>
                                                    <td>{$item.id}</td>
                                                    <td>{$item.openid}</td>
                                                    <td>{$item.startdate}</td>
                                                    <td>{$item.duration}</td>
                                                    <td>{$item.scores}</td>
                                                    <td><img src="{$item.reserve}" alt=""></td>
                                                    <td>{$item.nickname}</td>
                                                    <td style="width: 100px;">
                                                        <button type="button" onclick="return download_each({$item.id});" class="btn btn-info">导出</button>
                                                        <a type="button" href="javascript:;" onclick="deleteUser({$item['id']});" class="btn btn-danger">删除</a>
                                                    </td>
                                                </tr>
                                            </volist>
                                            </tbody>
                                        </table>
                                    </div>
                                    <div class="pages">
                                        {$page}
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {
        $('#myTab a:eq(2)').tab('show');//初始化显示哪个tab
    })

    $("#selectAll").click(function(){
        if($(this).prop('checked') == true){
            $("input[name=ids]").prop('checked',true);
        }else{
            $("input[name=ids]").prop('checked',false);
        }
    })

    $("#deleteAll").click(function(){
        if(!confirm('确认删除吗？')) return false;
        var ids = "";
        $("input[name=ids]").each(function() {
            if($(this).prop("checked")){
                ids += $(this).val() + "|";
            }
        });
        if(ids != ''){
            $.ajax({
                data: {ids: ids},
                dataType: 'json',
                url: '/User/Questionnaire/deleteUsers',
                type: 'get',
                success: function (res) {
                    alert(res['info']);
                    window.location.reload();
                }
            });
        }else{
            alert('请勾选用户！');
        }
    });

    function deleteUser(id){
        if(!confirm('确认删除吗？')) return false;
        $.ajax({
            data: {id: id},
            dataType: 'json',
            url: '/User/Questionnaire/deleteUser',
            type: 'get',
            success: function (res) {
                alert(res['info']);
                window.location.reload();
            }
        });
        return false;
    }

    function download(){
        //var data = $("form").serialize();
        var id = '<?php echo $id; ?>';
        var question3 = <?php echo I("get.question3", 0, "");?>;
        var value3 = <?php echo I("get.value3", 0, "");?>;
        window.location = '/User/Questionnaire/exportUser?id=' + id + "&question3=" + question3 + "&value3=" + value3;
        return false;
    }

    function download_each(fans_id){
        window.location = '/User/Questionnaire/exportDetail?id=' + fans_id;
        return false;
    }
    $("#question1").change(function(){
        $.ajax({
            data: {id: this.value},
            dataType: 'json',
            url: '/User/Questionnaire/getOption',
            type: 'get',
            success: function (res) {
                var option = "<option value='0'>--请选择--</option>";
                var value1 = <?php echo I("get.value1", 0, "");?>;
            if(res != []){
                for(var i=0; i < (res.length); i++){
                        option += "<option value='" + res[i]['id'] + "'"
                        if(value1 == res[i]['id']){
                            option += " selected ";
                        }
                        option += ">" + res[i]['title'] + "</option>";
                    }
                }
                $("#value1").html(option);
            }
        });
    });
    $("#question2").change(function(){
        $.ajax({
            data: {id: this.value},
            dataType: 'json',
            url: '/User/Questionnaire/getOption',
            type: 'get',
            success: function (res) {
                var option = "<option value='0'>--请选择--</option>";
                var value2 = <?php echo I("get.value2", 0, "");?>;
            if(res != []){
                for(var i=0; i < (res.length); i++){
                        option += "<option value='" + res[i]['id'] + "'"
                        if(value2 == res[i]['id']){
                            option += " selected ";
                        }
                        option += ">" + res[i]['title'] + "</option>";
                    }
                }
                $("#value2").html(option);
            }
        });
    });
    $("#question3").change(function(){
        $.ajax({
            data: {id: this.value},
            dataType: 'json',
            url: '/User/Questionnaire/getOption',
            type: 'get',
            success: function (res) {
                var option = "<option value='0'>--请选择--</option>";
                var value3 = <?php echo I("get.value3", 0, "");?>;
            if(res != []){
                for(var i=0; i < (res.length); i++){
                        option += "<option value='" + res[i]['id'] + "'"
                        if(value3 == res[i]['id']){
                            option += " selected ";
                        }
                        option += ">" + res[i]['title'] + "</option>";
                    }
                }
                $("#value3").html(option);
            }
        });
    });
    $("#filter").click(function(){

        var id = '<?php echo $id; ?>';

        var question1 = $("#question1").val();
        var question2 = $("#question2").val();
        var question3 = $("#question3").val();
        var value1 = $("#value1").val();
        var value2 = $("#value2").val();
        var value3 = $("#value3").val();
        window.location = "/User/Questionnaire/statisticsUser?id=" + id + "&question1=" + question1
            + "&question2=" + question2 + "&question3=" + question3 + "&value1=" + value1 + "&value2=" + value2
            + "&value3=" + value3;
        return false;
    });
    function empty_cond(){
        $("#question1").val(0);
        $("#question2").val(0);
        $("#question3").val(0);
        $("#value1").val(0);
        $("#value2").val(0);
        $("#value3").val(0);
        return false;
    }
    var question1 = <?php echo I("get.question1", 0, "");?>;
    $("#question1").val(question1);
    $("#question1").change();
    var question2 = <?php echo I("get.question2", 0, "");?>;
    $("#question2").val(question2);
    $("#question2").change();
    var question3 = <?php echo I("get.question3", 0, "");?>;
    $("#question3").val(question3);
    $("#question3").change();
</script>